package com.fit.exercise.msgp2p;

import java.io.Serializable;
import java.util.List;

public class PersonInfo implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2233657909953685411L;
	private String name;
	private String ipAddress;
	private Integer port;

	public PersonInfo(String name, String ipAddress, Integer port) {
		super();
		this.name = name;
		this.ipAddress = ipAddress;
		this.port = port;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getPort() {
		return port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	@Override
	public String toString() {
		return name + "," + ipAddress + "," + port;
	}

	public PersonInfo(String s) {
		String[] arr = s.split(",");
		try {
			name = arr[0];
			ipAddress = arr[1];
			port = Integer.parseInt(arr[2]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean equals(Object object) {

		if (object == this)
			return true;

		if (!(object instanceof PersonInfo))
			return false;

		PersonInfo person = (PersonInfo) object;

		if (this.getIpAddress() != null && this.port != null) {
			return this.getIpAddress().equalsIgnoreCase(person.getIpAddress()) ? this
					.getPort().compareTo(person.getPort()) == 0 : false;
		}
		return false;
	}
}
